package com.jack.leetcode.每日一题;

import java.util.ArrayList;
import java.util.List;

public class 对称二叉树 {

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.right = new TreeNode(2);
        root.left.left = new TreeNode(3);
        root.left.right = new TreeNode(4);
        root.right.left = new TreeNode(4);
        root.right.right = new TreeNode(3);
        System.out.println(isSymmetric(root));
    }

    public static boolean isSymmetric(TreeNode root) {
        if(root == null){
            return true;
        }
        return isSymTree(root,root);
    }

    private static boolean isSymTree(TreeNode l, TreeNode r){
        if(l == null && r == null){
            return true;
        }
        if(l == null || r == null){
            return false;
        }
        return l.val == r.val
                && isSymTree(l.left,r.right)
                && isSymTree(l.right,r.left);
    }
}
